package main.chapter5.equals;/**
 * @Author xy
 * @Date 2020/6/15 22:57
 * @Description
 */

import java.time.LocalDate;
import java.util.Objects;

/**
 * 文件名称： main.chapter5.equals.Employee.java</br>
 * 初始作者： xy</br>
 * 创建日期： 2020/6/15 22:57</br>
 * 功能说明： TODO <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者        日期       修改内容<br/>
 * ================================================<br/>
 * Copyright (c) 2020-2021 .All rights reserved.<br/>
 */
public class Employee {
    private String name;

    private double salary;

    private LocalDate hireDay;

    public Employee(String name, double salary, int year, int month, int day) {
        this.name = name;
        this.salary = salary;
        this.hireDay = LocalDate.of(year,month,day);
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public LocalDate getHireDay() {
        return hireDay;
    }

    public void raiseSalary(double byPercent){
        double raise = salary*byPercent/100;
        salary+=raise;
    }

    @Override
    public boolean equals(Object otherObject){
        if(this==otherObject){
            return true;
        }

        if(otherObject==null){
            return false;
        }

        if(getClass() != otherObject.getClass()){
            return false;
        }

        Employee other = (Employee)otherObject;

        return  Objects.equals(name,other.name) && salary==other.salary && Objects.equals(hireDay,other.hireDay);
    }

    @Override
    public int hashCode(){
        return Objects.hash(name,salary,hireDay);
    }

    @Override
    public String toString(){
        return getClass().getName()+"[name="+name+",salary="+salary+",hireDay="+hireDay+"]";
    }
}
